package com.ctshk.rpc.air.dto;

import com.ctshk.common.enums.NumberConstant;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Optional;

/**
 * @BelongsProject: ctshk-cloud
 * @BelongsPackage: com.ctshk.rpc.air.dto
 * @Author: hef
 * @CreateTime: 2021-05-20 11:04
 * @Description: 描述
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class AirProductChannelOnlineSelfPlatformDTO implements Serializable {
    @ApiModelProperty(value = "产品ID")
    private Long productId;

    @ApiModelProperty(value = "所属策略")
    private Long strategyId;

    @ApiModelProperty(value = "渠道id(主数据)")
    private Long channelId;

    @ApiModelProperty(value = "渠道名称")
    private String channelName;

    @ApiModelProperty(value = "加幅类型(1 数值，2百分比百分比增幅小数部分需向上取整，如1.56取2.00)")
    private Integer adjustType;

    @ApiModelProperty(value = "金额")
    private BigDecimal amount;

    @ApiModelProperty(value = "百分比")
    private Double percent;

    @ApiModelProperty(value = "去程金额")
    private BigDecimal tripAmount;

    @ApiModelProperty(value = "返程金额")
    private BigDecimal returnAmount;
    /**
     * （1 限购，2 不限购）
     */
    @ApiModelProperty(value = "是否设置限购")
    private Integer isLimit;

    @ApiModelProperty(value = "限购数量")
    private Integer limitNum;


    public BigDecimal calculateIncreasePrice(BigDecimal costPrice) {
        if (NumberConstant.ONE.getValue().equals(adjustType)) {
            costPrice = costPrice.add(Optional.ofNullable(amount).orElse(BigDecimal.ZERO));
        } else {
            costPrice = costPrice.add(costPrice.multiply(BigDecimal.valueOf(Optional.ofNullable(percent).orElse(0D)).divide(BigDecimal.valueOf(100))));
        }
        return costPrice;
    }
}
